﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using School.Entities;
using System.Globalization;

namespace School.Service.BOOKS
{
   public class SRV_Book_StockTacking
    {
        private static SchoolEntities db = new SchoolEntities();

        public static bool SRV_Book_STOCKTACKINGInsert(List<SRV_BOOK_STOCKTACKING> lstStock)
        {
            foreach (SRV_BOOK_STOCKTACKING item in lstStock)
            {
                db.AddToSRV_BOOK_STOCKTACKING(item);
            }
            try
            {
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool BookEquakity(List<string> lstbookCode, DateTime date)
        {
            CultureInfo SaCulture = new CultureInfo("ar-eg");
            DateTimeFormatInfo hijriDateInfo = SaCulture.DateTimeFormat;
            hijriDateInfo.ShortDatePattern = "MM/dd/yyyy";
            foreach (string Bookcode in lstbookCode)
            {
                db.SRV_Book.Where(s => s.Code == Bookcode).First().BookQty =
                    db.SRV_BOOK_STOCKTACKING.Where(s => s.SRV_Book.Code == Bookcode &&
                        s.Date_Time == date).First().Pysical_Qty;
                db.SRV_BOOK_STOCKTACKING.Where(s => s.SRV_Book.Code == Bookcode &&
                      s.Date_Time == date).First().Equating_Date_Time = Convert.ToDateTime(DateTime.Now.ToShortDateString(), hijriDateInfo);
            }

            try
            {
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
